<template>
    <div class="out-style">
        <div class="div-form">
            <span class="span-first">基本信息</span>
            <Divider/>
            <Form :model="formItem" :label-width="100">
                <FormItem label="优惠券名称:" prop="name">
                    <Input v-model="formItem.name" placeholder="请输入商品名称" class="input-one"></Input>
                </FormItem>
                <FormItem label="名称备注:" prop="remarks">
                    <Input v-model="formItem.remarks" placeholder="请输入名称备注" class="input-one"></Input>
                </FormItem>
                <FormItem label="发放总量:" prop="stock">
                    <Input v-model="formItem.stock" placeholder="请输入商品发放量" class="input-two"></Input>
                    <span class="unit">张</span>
                    <div class="tips-font">
                        <span>修改优惠券总量时只能增加不能减少，请谨慎设置</span>
                    </div>
                </FormItem>
                <FormItem label="适用店铺:" prop="">
                    <span class="span-style">选择店铺</span>
                </FormItem>
                <FormItem label="适用商品:" prop="available_goods">
                    <span class="tips-font">全部商品包括网店商品和门店商品，若部门商品不可用则默认其余门店商品及全部网店商品可用该券。</span>
                    <br/>
                    <RadioGroup v-model="formItem.available_goods" vertical>
                        <Radio label="0">
                            <span>全部商品可用</span>
                        </Radio>
                        <!--<Radio label="android">
                            <span>指定商品可用</span>
                        </Radio>
                        <Radio label="windows">
                            <span>指定商品不可用</span>
                        </Radio>-->
                    </RadioGroup>
                </FormItem>
                <FormItem label="使用门槛:" prop="amount">
                    <RadioGroup v-model="radioThreshold" vertical>
                        <Radio label="0">
                            <span>无使用门槛</span>
                        </Radio>
                        <Radio label="1">
                            <span>订单满</span>
                            <Input class="input-three" :disabled="change" v-model="formItem.amount"></Input>
                            <span class="unit">元</span>
                        </Radio>
                    </RadioGroup>
                </FormItem>
                <FormItem label="优惠内容:" prop="reduce_amount">
                    <div>
                        <span>减免</span>
                        <Input v-model="formItem.reduce_amount" placeholder="" class="input-three"></Input>
                        <span class="unit">元</span>
                    </div>
                </FormItem>
                <FormItem label="用券时间:" prop="radioChooseTime">
                    <RadioGroup v-model="radioChooseTime" vertical>
                        <Radio label="0">
                            <DatePicker type="datetime" v-model="formItem.start_date" :disabled="changeTime" ></DatePicker>
                            <span>至</span>
                            <DatePicker type="datetime" v-model="formItem.end_date" :disabled="changeTime"></DatePicker>
                        </Radio>
                        <Radio label="1" disabled>
                            <span>领券当日起</span>
                            <Input  placeholder="" class="input-three"
                                   :disabled="changeTime1"></Input>
                            <span class="unit">天内可用</span>
                            <Icon type="md-help-circle" class="excel-help"/>
                        </Radio>
                        <Radio label="2" disabled>
                            <span>领券次日起</span>
                            <Input  placeholder="" class="input-three"
                                   :disabled="changeTime2"></Input>
                            <span class="unit">天内可用</span>
                            <Icon type="md-help-circle" class="excel-help"/>
                        </Radio>
                    </RadioGroup>
                </FormItem>
                <FormItem label="领取人限制:" prop="receiver_restrict">
                    <RadioGroup v-model="formItem.receiver_restrict" vertical>
                        <Radio label="0">
                            <span>不限制，所有人可领取</span>
                        </Radio>
                        <Radio label="1">
                            <span>指定客户身份可领</span>
                        </Radio>
                    </RadioGroup>
                    <div class="tips-font">编辑保存后，仅对后续领取的客户生效，对之前已领取的客户无法生效</div>
                </FormItem>
                <FormItem label="每人限领次数:" prop="limit_count">
                    <RadioGroup v-model="radioLimit" vertical>
                        <Radio label="0">
                            <span>不限次数</span>
                        </Radio>
                        <Radio label="1">
                            <Input v-model="formItem.limit_count" style="width: 100px" :disabled="change3"></Input>
                            <span class="unit">次</span>
                        </Radio>
                    </RadioGroup>
                    <div class="tips-font">编辑保存后，仅对后续领取的客户生效，对之前已领取的客户无法生效</div>
                </FormItem>
            </Form>
            <div class="foot-btn">
                <Button @click="save(formItem)">保存</Button>
                <Button>取消</Button>
            </div>
        </div>
        <div class="right-div">
            <div class="head-div"></div>
            <div class="body-div">
                <div class="text-div">{{formItem.name}}</div>
                <div class="text-div1" v-if="formItem.reduce_amount!==''">减免{{formItem.reduce_amount}}元优惠券</div>
                <div class="text-div2" v-if="radioThreshold==='0'">无限制</div>
                <div class="text-div2" v-else-if="radioThreshold==='1'&&formItem.amount!==''">满{{formItem.amount}}元</div>
                <div class="data-style" v-if="formItem.start_date!==''">有效日期:{{timeChange}}-{{endTimeChange}}</div>
            </div>
            <p>使用说明</p>
            <div class="foot-div">
                <div>{{formItem.name}}</div>
                <div v-if="formItem.start_date!==''">活动时间:{{timeChange}}到{{endTimeChange}}</div>
                <div v-if="formItem.name!==''" class="discount-style">优惠内容：{{content}}
                    <div v-if="radioThreshold==='0'">，无限制</div>
                    <div v-else-if="radioThreshold==='1'&&formItem.amount!==''">，满{{formItem.amount}}元</div>
                    <div v-if="formItem.reduce_amount!==''">，减免{{formItem.reduce_amount}}元优惠券</div>
                </div>
            </div>
        </div>
    </div>
</template>
<script>
import { marketingCouponServiceInsert } from '@/api/shop'
export default {
  data () {
    return {
      radioChoose: '全部商品可用',
      radioChooseThreshold: '0',
      radioChooseTime: '0',
      radioThreshold: '0',
      radioLimit: '0',
      startTime: '',
      endTime: '',
      formItem: {
        type: 'FULLREDUCE',
        receiver_restrict: '',
        name: '',
        remarkName: '',
        stock: '',
        available_goods: '',
        amount: '',
        reduce_amount: '',
        useTime: '',
        start_date: '',
        end_date: '',
        limit_count: '',
        discount_limit: '',
        status: 'NORMAL'
      }
    }
  },
  methods: {
    save (formItem) {
      if (formItem.amount === '') {
        this.formItem.amount = '0'
      }
      if (formItem.limit_count === '') {
        this.formItem.limit_count = '0'
      }
      marketingCouponServiceInsert(formItem).then(ret => {
        let data = ret.data
        if (data.errcode === 0) {
          this.success()
          this.$router.push({
            name: 'shopCoupon'
          })
        } else {
          this.error(data)
        }
      })
    },
    success (val) {
      val = this.$common.xeUtils.isEmpty(val) ? '添加成功' : val
      this.$Message.success(val)
    },
    error (data) {
      this.$Message.error({
        content: '操作失败,\n' + data.errmsg
      })
    }
  },
  computed: {
    change () {
      return this.radioThreshold !== '1'
    },
    changeTime () {
      return this.radioChooseTime !== '0'
    },
    changeTime1 () {
      return this.radioChooseTime !== '1'
    },
    changeTime2 () {
      return this.radioChooseTime !== '2'
    },
    change3 () {
      return this.radioLimit !== '1'
    },
    timeChange () {
      return this.$common.xeUtils.toDateString(this.formItem.start_date)
    },
    endTimeChange () {
      return this.$common.xeUtils.toDateString(this.formItem.end_date)
    },
    content () {
      if (this.formItem.available_goods === '0') {
        return '全部商品可用'
      }
      return ''
    }
  },
  mounted () {
  }
}
</script>

<style scoped lang="less">
    .discount-style{
        display: flex;
    }
    .data-style{
        color: #FFADAF;
        margin-top: 10px;
      text-align: center;
    }
    .text-div2{
        color: #FFFFFF;
        text-align: center;
        margin-top: 10px;
    }
    .text-div1 {
        text-align: center;
        color: #FFFFFF;
        font-size: 30px;
    }

    .text-div {
        padding: 10px 0 0 10px;
        font-size: 20px;
        color: #FFFFFF;
    }

    .out-style {
        display: flex;
        margin-bottom: 50px;
    }

    .right-div {
        width: 400px;
        height: 600px;
        margin: 0 auto;
        background-color: #F9F9F9;
        border: 1px solid #C5C5C5;
        border-top: none;
    }

    .head-div {
        width: 100%;
        height: 60px;
        background-color: #333333;

    }

    .body-div {
        margin-top: 50px;
        width: 100%;
        height: 200px;
        background-color: #FE4758;
    }

    .body-div span {
        font-size: 20px;
        color: #FFFFFF;
    }

    .foot-div {
        width: 100%;
        min-height: 50px;
        border: 1px solid #F9F9F9;
        background-color: #FFFFFF;
        line-height: 1.5em;
    }

    .excel-help {
        margin-left: 10px;
        color: #C7C7C8;
        cursor: pointer;
    }

    .div-form {
        margin: 0 20px;
    }

    .span-first {
        font-size: 16px;
        font-weight: 600;
    }

    .input-one {
        width: 400px;
    }

    .input-two {
        width: 160px;
    }

    .input-three {
        width: 100px;
        margin-left: 5px;
    }

    .tips-font-one {
        font-size: 12px;
        color: #155BD4;
    }

    .unit {
        margin-left: 5px;
    }

    .tips-font span {
        font-size: 12px;
        color: #969799;
    }

    .tips-font {
        font-size: 12px;
        color: #969799;
    }

    .span-style {
        color: #155BD4;
    }

    /deep/ .ivu-radio-group-vertical .ivu-radio-wrapper {
        height: 40px;
    }

    .foot-btn {
         text-align: center;
     }

    .foot-btn Button {
        margin-left: 30px;
    }
</style>
